package	com.mes.web.controller.jyy;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mes.entity.jyy.StaffInformation;
import com.mes.entity.tdd.Staff;
import com.mes.service.jyy.StaffInformationService;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;
/**
 *
 *@ClassName: StaffInformationController
 *@Description: 员工信息填报
 *@Author jyy
 *@Date 2019-05-29 13:45:36
 *@version 1.0
*/
@Controller
@RequestMapping("/staffInformation")
public class StaffInformationController{
	@Resource StaffInformationService staffInformationService;
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/page")
	public String pageStaffInformation (Model model) {
		return "/jy/momv2/staffInformation";
	}
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	@RequestMapping("/queryById")
	@ResponseBody
	public StaffInformation queryById(Long id) {
		StaffInformation param = staffInformationService.queryById(id);
		return param;
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<StaffInformation> queryAllByMution(StaffInformation param) {
		List<StaffInformation> list = staffInformationService.queryAllByMution(param);
		return list;
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/list")
	public void list(StaffInformation param,HttpServletResponse response) throws Exception{
		/*
		 * 条件分页查询内容
		 */
		List<StaffInformation> list = staffInformationService.findPageByMution(param);
		/*
		 * 条件查询总条数
		 */
		Integer total = staffInformationService.selectCountByMution(param);
		
		JSONObject jsonObject=new JSONObject();
		jsonObject.put("total", total);
		jsonObject.put("rows", list);
		ResponseUtil.write(response, jsonObject);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/insert")
	public void insert(StaffInformation param, HttpServletResponse response, HttpSession session) throws Exception{
		
		Staff staff = (Staff) session.getAttribute("staff");
		if(staff != null) {
			param.setSid(staff.getStaffid());
		}
		
		Long id = staffInformationService.insert(param);
		response.getWriter().print(id);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/update")
	public void update(StaffInformation param,HttpServletResponse response) throws Exception{
		Integer count = staffInformationService.update(param);
		response.getWriter().print(count);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = staffInformationService.delete(ids);
		response.getWriter().print(count);
	}
}
